home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / utils / adt / regproc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.4 KB  |  158 lines

  1. /*
  2.  * regproc.c --
  3.  *     Functions for the built-in type "RegProcedure".
  4.  */
  5.  
  6. #include <strings.h>
  7.  
  8. #include "tmp/postgres.h"
  9.  
  10. RcsId("$Header: /private/postgres/src/utils/adt/RCS/regproc.c,v 1.12 1992/01/30 20:40:27 mer Exp $");
  11.  
  12. #include "access/heapam.h"
  13. #include "access/relscan.h"
  14. #include "access/skey.h"
  15. #include "access/tqual.h"    /* for NowTimeQual */
  16. #include "utils/fmgr.h"
  17. #include "utils/log.h"
  18.  
  19. #include "catalog/catname.h"
  20.  
  21.         /* ========== USER I/O ROUTINES ========== */
  22.  
  23.  
  24. /*
  25.  *    regprocin    - converts "proname" to proid
  26.  *
  27.  *    proid of NULL signifies unknown
  28.  */
  29. int32
  30. regprocin(proname)
  31.     char    *proname;
  32. {
  33.     Relation    proc;
  34.     HeapScanDesc    procscan;
  35.     HeapTuple    proctup;
  36.     ScanKeyEntryData    key;        /* static better ??? */
  37.     RegProcedure    result;
  38.     Boolean        isnull;
  39.  
  40.     if (proname == NULL)
  41.         return(0);
  42.     proc = amopenr(ProcedureRelationName->data);
  43.     if (!RelationIsValid(proc)) {
  44.         elog(WARN, "regprocin: could not open %s",
  45.              ProcedureRelationName->data);
  46.         return(0);
  47.     }
  48.     ScanKeyEntryInitialize(&key, 
  49.                    (bits16)0, 
  50.                    (AttributeNumber)1, 
  51.                    (RegProcedure)F_CHAR16EQ,
  52.                    (Datum)proname);
  53.  
  54.     procscan = ambeginscan(proc, 0, NowTimeQual, 1, &key);
  55.     if (!HeapScanIsValid(procscan)) {
  56.         amclose(proc);
  57.         elog(WARN, "regprocin: could not being scan of %s",
  58.              ProcedureRelationName);
  59.         return(0);
  60.     }
  61.     proctup = amgetnext(procscan, 0, (Buffer *) NULL);
  62.     switch (HeapTupleIsValid(proctup)) {
  63.     case 1:
  64.         result = (RegProcedure) amgetattr(proctup,
  65.                           InvalidBuffer,
  66.                           ObjectIdAttributeNumber,
  67.                           &proc->rd_att,
  68.                           &isnull);
  69.         if (isnull) {
  70.             elog(FATAL, "regprocin: null procedure %s", proname);
  71.         }
  72.         break;
  73.     case 0:
  74.         result = (RegProcedure) 0;
  75. #ifdef    EBUG
  76.         elog(DEBUG, "regprocin: no such procedure %s", proname);
  77. #endif    /* defined(EBUG) */
  78.     }
  79.     amendscan(procscan);
  80.     amclose(proc);
  81.     return((int32) result);
  82. }
  83.  
  84. /*
  85.  *    regprocout    - converts proid to "proname"
  86.  */
  87. char *
  88. regprocout(proid)
  89.     RegProcedure proid;
  90. {
  91.     Relation    proc;
  92.     HeapScanDesc    procscan;
  93.     HeapTuple    proctup;
  94.     char        *result;
  95.     ScanKeyEntryData    key;
  96.     extern        bzero();
  97.  
  98.     result = (char *)palloc(16);
  99.     proc = amopenr(ProcedureRelationName->data);
  100.     if (!RelationIsValid(proc)) {
  101.         elog(WARN, "regprocout: could not open %s",
  102.              ProcedureRelationName->data);
  103.         return(0);
  104.     }
  105.     ScanKeyEntryInitialize(&key,
  106.                    (bits16)0,
  107.                    (AttributeNumber)ObjectIdAttributeNumber,
  108.                    (RegProcedure)F_INT4EQ,
  109.                    (Datum)proid);
  110.  
  111.     procscan = ambeginscan(proc, 0, NowTimeQual, 1, &key);
  112.     if (!HeapScanIsValid(procscan)) {
  113.         amclose(proc);
  114.         elog(WARN, "regprocin: could not being scan of %s",
  115.              ProcedureRelationName);
  116.         return(0);
  117.     }
  118.     proctup = amgetnext(procscan, 0, (Buffer *)NULL);
  119.     switch (HeapTupleIsValid(proctup)) {
  120.         char    *s;
  121.         Boolean    isnull;
  122.     case 1:
  123.         s = (char *) amgetattr(proctup, InvalidBuffer, 1,
  124.                        &proc->rd_att, &isnull);
  125.         if (!isnull) {
  126.             strncpy(result, s, 16);
  127.             break;
  128.         }
  129.         elog(FATAL, "regprocout: null procedure %d", proid);
  130.         /*FALLTHROUGH*/
  131.     case 0:
  132.         bzero(result, 16);
  133.         result[0] = '-';
  134. #ifdef    EBUG
  135.         elog(DEBUG, "regprocout: no such procedure %d", proid);
  136. #endif    /* defined(EBUG) */
  137.     }
  138.     amendscan(procscan);
  139.     amclose(proc);
  140.     return(result);
  141. }
  142.  
  143.  
  144.          /* ========== PUBLIC ROUTINES ========== */
  145.  
  146. ObjectId
  147. RegprocToOid(rp)
  148.     RegProcedure rp;
  149. {
  150.     return (ObjectId)rp;
  151. }
  152.  
  153.      /* (see int.c for comparison/operation routines) */
  154.  
  155.  
  156.          /* ========== PRIVATE ROUTINES ========== */
  157.  
  158.